package com.gcb.common.enums;

import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

@Getter
public enum AuditSourceEnum {
    WX(1, "微信分享"),
    QRCODE(2, "企业二维码");

    private final Integer code;
    private final String info;

    AuditSourceEnum(Integer code, String info) {
        this.code = code;
        this.info = info;
    }


    public static String getInfo(String type) {
        return Optional.ofNullable(of(Integer.valueOf(type)))
                .map(AuditSourceEnum::getInfo)
                .orElse("");
    }

    public static String getInfo(Integer type) {
        return Optional.ofNullable(of(type))
                .map(AuditSourceEnum::getInfo)
                .orElse("");
    }

    public static AuditSourceEnum of(Integer code) {
        Optional<AuditSourceEnum> first = Arrays.stream(AuditSourceEnum.values()).filter(v -> v.getCode().equals(code)).findFirst();
        return first.orElse(null);
    }
}
